package com.swq.java.code.chapter11.code10;

import java.util.Calendar;
import java.util.Date;

public final class Schedule {
    private final Date start;
    private final Date end;

    public Schedule(Date start, Date end) {
        //不允许放假日期在开学日期的前面
        if (start.compareTo(end) > 0) throw new IllegalArgumentException(start + " after " + end);
        this.start = start;  //采用保护性拷贝
        this.end = end;   //采用保护性拷贝
    }

    public Date getStart() {
        return start;
    }  //采用保护性拷贝

    public Date getEnd() {
        return end;
    }  //采用保护性拷贝

    @Override
    public String toString() {
        return start+"==>"+end;
    }

    public static void main(String args[]) {
        Calendar c = Calendar.getInstance();
        c.set(2006, 9, 1);
        Date start = c.getTime();
        c.set(2007, 1, 25);
        Date end = c.getTime();
        Schedule s = new Schedule(start, end);
        System.out.println(s);
        end.setTime(System.currentTimeMillis());  //修改放假时间
        start = s.getStart();
        start.setTime(System.currentTimeMillis());  //修改开学时间
        System.out.println(s);
    }
}
